package com.zzjson.springbootjdbc.controller;

import com.zzjson.springbootjdbc.domain.User;
import com.zzjson.springbootjdbc.repository.UserRepository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.springbootjdbc.controller</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月04日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@RestController
public class UserController {
	private final UserRepository userRepository;

	private final ExecutorService executorService = Executors.newFixedThreadPool(5);

	public UserController(UserRepository userRepository) {
		this.userRepository = userRepository;
	}

	@RequestMapping
	public Boolean saveUser(@RequestBody User user) throws ExecutionException, InterruptedException {
		Future<Boolean> submit = executorService.submit(() -> {
			return userRepository.save(user);
		});
		return submit.get();

	}
}